package callback;

public class Main {
    
    private static WeatherCallback display1 = new WeatherCallback() {
        @Override
        public void onWeatherChanged(float temperature, float humidity) {
            System.out.println("our警告1: Temperature is " + temperature + "°C");
        }
    };
    
    public static void main(String[] args) {
        WeatherStation weatherStation1 = new WeatherStation();
        
        WeatherStation weatherStation2 = new WeatherStation();
        
        // WeatherDisplay display1 = new WeatherDisplay("Display 1");
        // WeatherDisplay display2 = new WeatherDisplay("Display 2");

        weatherStation1.registerCallback(display1);
        weatherStation1.registerCallback((float temperature, float humidity) -> {
            System.out.println("警告1: Temperature is " + temperature + "°C");
        });
        // weatherStation.registerCallback(display2);

        // 注册监听器
        weatherStation1.registerCallback(new WeatherCallback() {
            @Override
            public void onWeatherChanged(float temperature, float humidity) {
                System.out.println("警告2: Temperature is " + temperature + "°C");
            }
        });
        
        // 测试天气更新
        weatherStation1.setMeasurements(25.2f, 65.0f);
        weatherStation1.setMeasurements(26.5f, 70.0f);
        
        // 移除一个显示器
        weatherStation1.removeCallback(display1);
        weatherStation1.setMeasurements(24.9f, 63.0f);

        weatherStation2.registerCallback(new WeatherCallback() {
            @Override
            public void onWeatherChanged(float temperature, float humidity) {
                System.out.println("警告3: Temperature is " + temperature + "°C");
            }
        });
        weatherStation2.setMeasurements(25.2f, 65.0f);
    }
}
